package com.hq.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hq.mapper.DoctorMapper;
import com.hq.pojo.Appointment;
import com.hq.pojo.Doctor;
import com.hq.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DoctorServiceImpl implements DoctorService {

    @Autowired
    private DoctorMapper doctorMapper;
//医生查询自己个人信息
    @Override
    public PageInfo<Doctor> queryMyInformation(String username) {
        List<Doctor> doctors = doctorMapper.queryMyInformation(username);
        return new PageInfo<>(doctors);
    }
    //   修改医生个人信息
    @Override
    public Map<String,String> updateDoctor(Doctor doctor) {
        Map<String,String> map = new HashMap<>();
        int i  =  doctorMapper.updateDoctor(doctor);
        if (i>0){
            map.put("code","修改成功");
            System.out.println("修改成功");
            return map;
        }else {
            System.out.println("修改失败");
            map.put("code","修改失败");
            return map;
        }
    }





    @Override
    public PageInfo<Appointment> selectAllMaser(int pageNum, int pageSize, String doctorName) {

        // 使用pageHelper插件实现分页   开启分页
        PageHelper.startPage(pageNum, pageSize);

        Doctor doctor = doctorMapper.queryDoctor(doctorName);

        // 查询数据库，获取查询数据
        List<Appointment> userList = doctorMapper.selectAllMaser(doctor.getName());

        // 封装查询的数据在pageInfo对象中
        return new PageInfo<>(userList);
    }

    @Override
    public void delOne(Integer appointId) {
        doctorMapper.delOne(appointId);
    }

    @Override
    public void reply(Integer appointId) {

    }


}
